<?
include('header.php');
$tsite = $site->site_url;



  $site2 = mysql_query("SELECT * FROM `stumbleupon` WHERE (`active` = '0' AND `points` >= `cpc`) AND (`id` NOT IN (SELECT `site_id` FROM `stumbled` WHERE `user_id`='{$data['id']}') AND `user`!='{$data['id']}') ORDER BY `cpc` DESC LIMIT 0, 20");
  $ext = mysql_num_rows($site2);
  
?>
<div class="block medium right">
			<div class="top"><?if(isset($data['id'])) {?>	
                  <h1>Earn Coins - Stumbleupon</h1>
            </div>
			<div class="content">	
<?
if($ext > 0){
?>
<br>
<p>Press "Follow" on the user, then press "Follow" on Stumbleupon's page. After that, press "Confirm".</p>
<script language="javascript">
            function refreshpage()
            {
                window.location.reload();
            }
            
            function stumbleuser(str, id)
            {  
               
                
                document.getElementById("Hint").style.display='block';
                $("#Hint").html('We are verifying your Follow...');
                $.ajax({
                    type: "GET",
                    url: "stumbled.php",
                    data: "me="+str+"&him="+id+"&count="+count,
                    success: function(msg){
                        $("#Hint").html(msg);
                        removeElement('boxes', id);
                    }
                });
            }
            var count = 1000000;
            function stumbleopen(id)
            {
                document.getElementById("Hint").style.display='block';
                $("#Hint").html('We are connecting to Stumbleupon...');
                $.ajax({
                    type: "GET",
                    url: "stumbleuponfollowercount.php",
                    data: "url="+id,
                    success: function(msg){
                        if(!isNaN(msg))
                        {
                            $("#Hint").html('SUCCESS: We have connected to Stumbleupon...');
                            count = msg;
                            
                        }
                        else
                        {
                            $("#Hint").html('We cannot connect to Stumbleupon...');
                        }
                    }
                });
            }
            
            function removeElement(parentDiv, childDiv){
                if (document.getElementById(childDiv)) {     
                    var child = document.getElementById(childDiv);
                    var parent = document.getElementById(parentDiv);
                    parent.removeChild(child);
                }
            }
            </script>
<center><div id="txtHint" style="display:none;"></div></center>
<center><div id="Hint" class="hint"></div></center>
<div id="boxes">
<?
  for($j=1; $site = mysql_fetch_object($site2); $j++){


?>                                                                                                                                                                                                                              	                                                                                                                                                                                                                                        
<div class="follow" id="<? echo $site2->id;?>"><b><? echo $site->title;?></b><br><div class="points" id="<? echo $site2->id;?>points">Coins: <b><? echo $site->cpc;?></b></div><br><center><a href="javascript:void(0);" onclick="stumbleopen('<? echo $site->site;?>'),window.open('<? echo $site->site;?>','Stumbleupon','status=0,toolbar=0,width=1000,height=500,resizable=0,menubar=0,location=0,directories=0');" class="followbutton">Follow</a>
<a href="javascript:void(0);" onclick="stumbleuser('<? echo $data['id'];?>','<? echo $site->id;?>');" class="followbutton">Confirm</a>
</center><font style="font-size:0.8em;">[<a href="javascript:void(0);" onclick="skipuser('<? echo $site2->id;?>','<? echo $site2->title;?>');remove('6923');" style="color: #666666;font-size:0.9em;">skip</a>]</font></center></div>
<?}?>
</div>
<br>
<div class='infobox'>Follow the users and refresh page to see the addition of Coins!<br>
<input onclick='refreshpage();' class="refresh" type='button' value='Refresh'>
</form></div>
<?}else{?>
<br>
<div class="msg">
<div class="error">Sorry, there are no more coins to be earned at the moment. Please try again later.</div>
<div class="info"><a href="buycoins.php"><b>Feel like you need more coins? You can purchase them now!</b></a></div></div>
<?}}else{?><script>document.location.href='index.php'</script><?}?>
				</div>
			</div>		
<?include('footer.php');?>